using ASP;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Shop_Member_Shop_ManageFProductClass : Member, IRequiresSessionState
{
	protected TextBox TxtF_ProductClassName;
	protected RequiredFieldValidator Rq1;
	protected TextBox TxtF_ProductClassRemark;
	protected Button ButUpdate;
	protected Button ButADD;
	protected Label LabErro;
	protected TextBox TXTPROCLASSID;
	protected GridView GridView1;
	protected ObjectDataSource ObjectDataSource1;
	private int UserID = 0;
	private int F_ProductClassID = 0;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.UserID = base.user.UserID;
		if (!base.IsPostBack)
		{
			if (base.Request["F_ProductClassID"] != null)
			{
				this.F_ProductClassID = int.Parse(base.Request["F_ProductClassID"].ToString());
				Shop_FProductClass shop_FProductClass = new Shop_FProductClass();
				DataRow dataRow = shop_FProductClass.GetFProductClassByProductClassID(this.F_ProductClassID).Rows[0];
				this.TxtF_ProductClassName.Text = dataRow["F_ProductClassName"].ToString();
				this.TxtF_ProductClassRemark.Text = dataRow["F_ProductClassRemark"].ToString();
				this.TXTPROCLASSID.Text = this.F_ProductClassID.ToString();
				this.ButADD.Visible = false;
				this.ButUpdate.Visible = true;
			}
			else
			{
				this.ButADD.Visible = true;
				this.ButUpdate.Visible = false;
			}
		}
	}
	protected void GridView1_DataBound(object sender, EventArgs e)
	{
		foreach (GridViewRow gridViewRow in this.GridView1.Rows)
		{
			Shop_MyFavourite shop_MyFavourite = new Shop_MyFavourite();
			gridViewRow.Cells[2].Text = shop_MyFavourite.GetProductCountByClassID(this.UserID, int.Parse(gridViewRow.Cells[0].Text)).ToString();
		}
	}
	protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
	{
		Shop_FProductClass shop_FProductClass = new Shop_FProductClass();
		shop_FProductClass.DeleteFProductClass(int.Parse(this.GridView1.SelectedRow.Cells[0].Text.ToString()));
		this.ObjectDataSource1.Update();
	}
	protected void ButUpdate_Click(object sender, EventArgs e)
	{
		if (this.TxtF_ProductClassName.Text.Length > 6)
		{
			this.LabErro.Text = "不能超过6个字符或汉字";
		}
		else
		{
			Shop_FProductClass shop_FProductClass = new Shop_FProductClass();
			shop_FProductClass.UpdateFProductClass(this.TxtF_ProductClassName.Text, this.TxtF_ProductClassRemark.Text, int.Parse(this.TXTPROCLASSID.Text));
			this.ObjectDataSource1.Update();
			this.ButADD.Visible = true;
			this.ButUpdate.Visible = false;
			this.LabErro.Text = "";
			this.TxtF_ProductClassName.Text = "";
			this.TxtF_ProductClassRemark.Text = "";
		}
	}
	protected void ButADD_Click(object sender, EventArgs e)
	{
		if (this.TxtF_ProductClassName.Text.Length > 6)
		{
			this.LabErro.Text = "不能超过6个字符或汉字";
		}
		else
		{
			Shop_FProductClass shop_FProductClass = new Shop_FProductClass();
			if (shop_FProductClass.GetFProductClassByUserID(this.UserID).Rows.Count >= 5)
			{
				this.LabErro.Text = "类别最多只能添加5个";
			}
			else
			{
				shop_FProductClass.InsertFProductClass(this.TxtF_ProductClassName.Text, this.UserID, this.TxtF_ProductClassRemark.Text);
				this.ObjectDataSource1.Update();
				this.LabErro.Text = "";
				base.Response.Redirect("Shop_MyFavourite.aspx?tag=0");
			}
		}
	}
}
